<?php

require_once(dirname(__FILE__) . '/discuz_publish.php');

$base_url = "http://blog.csdn.net/manoel/article/details/7579109";


function parse_content($content, $start_tag, $end_tag)
{
	$content = substr($content, stripos($content, $start_tag)+strlen($start_tag));
	$content = substr($content, 0, stripos($content, $end_tag));

	return $content;
}

function preg_title($content)
{
	preg_match_all('/<span class="link_title"><a href=".*?">([^~]*?)<\/a><\/span>/', $content, $matches);

	return $matches[1][0];
}

function get_next($content)
{
	preg_match_all('/<li class="next_article">[^~]*?<span>.*?<\/span><a href="(.*?)">(.*?)<\/a><\/li>/', $content, $matches);
	
	if($matches[1][0])
	{
		return array($matches[1][0], $matches[2][0]);
	}
	else
	{
		return array();
	}
	//($matches);
}


do {
$content = file_get_contents($base_url);
file_put_contents( dirname(__FILE__ ) . '/log', $content . '{br}'); //exit(0);

$title = trim(preg_title($content));

$cont = parse_content($content, '<div id="article_content" class="article_content">', '<div class="share_buttons" id="sharePanel"></div>');

discuz_post_publish(escape_s($title), escape_s($cont), 85);

$next = get_next($content);

if(!empty($next))
{
	$base_url = $next[0];
}
}
while(!empty($next));

function escape_s($content)
{
	/*
	$content = str_replace( "'", "\'", $content);
	$content = str_replace('"', '\"', $content);
	$content = str_replace('<br />', '', $content);
	$content = preg_replace('/<div.*?>/i', '', $content);
	$content = preg_replace('/<\/div>/i', '', $content);*/
	return $content;
}
//var_dump($next);




?>